class PlayersController < ApplicationController
	def create
    @club = Club.find(params[:club_id])
    @player = @club.players.create(player_params)
    redirect_to club_path(@club)
  end

  def edit
    @club = Club.find(params[:club_id])
    @player = @club.players.find(params[:id])
  end

  def update
    @player = Player.find(params[:id])
    
    if @player.update(player_params)
      redirect_to club_path(@player.club)
    else
      render 'edit'
    end
  end

  def destroy
    @club = Club.find(params[:club_id])
    @player = @club.players.find(params[:id])
    @player.destroy
    redirect_to club_path(@club)
  end
 
  private
    def player_params
      params.require(:player).permit(:first_name, :last_name, :age, :last_score, :average_score, :price)
    end
end
